/*
 * @Description: 未注册状态首页
 * @version: 
 * @Company: C20出行
 * @Author: ZhengZhuang
 * @Date: 2019-08-21 09:53:37
 * @LastAuthor   : zhengzhuang
 * @lastTime     : 2019-12-27 13:32:54
 */
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/service/request.dart';
import 'package:provider/provider.dart';
import 'package:C20Driver/provider/driver_information.dart';
import 'package:C20Driver/routers/navigator_util.dart';

class UnregisteredHome extends StatefulWidget {
  @override
  _UnregisteredHomeState createState() => _UnregisteredHomeState();
}

class _UnregisteredHomeState extends State<UnregisteredHome> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: EasyRefresh.custom(
        enableControlFinishRefresh: false,
        enableControlFinishLoad: true,
        onRefresh: () async {
          Request.getSetDriverInfo(context);
        },
        header: ClassicalHeader(
          enableInfiniteRefresh: false,
          refreshText: "下拉刷新",
          refreshReadyText: "松开刷新",
          refreshingText: "刷新中",
          refreshedText: "刷新成功",
          refreshFailedText: "刷新失败",
          showInfo: false,
        ),
        slivers: <Widget>[
          SliverList(
            delegate: SliverChildListDelegate([
              Column(
                children: <Widget>[
                  SizedBox(
                    height: ScreenUtil().setWidth(40),
                  ),
                  propagandaBanner(),
                  toRegister(),
                  commonProblem(),
                ],
              ),
            ]),
          ),
        ],
      ),
    );
  }

  // 立即注册赚钱
  Widget toRegister() {
    return Container(
      width: ScreenUtil().setWidth(700.0),
      height: ScreenUtil().setHeight(160.0),
      margin: EdgeInsets.all(ScreenUtil().setWidth(25.0)),
      decoration: BoxDecoration(
        color: Color(0xffF6F8FC),
        borderRadius: BorderRadius.circular(ScreenUtil().setWidth(32)),
      ),
      child: Consumer<DriverInformation>(builder: (ctx, state, child) {
        return _stateJudgment(state.driverInfo.authenticationStatus);
        // return _unregisteredStatus();
      }),
    );
  }

  _stateJudgment(String authenticationStatus) {
    // return _auditFailed();
    if (authenticationStatus == '0090') return _unregisteredStatus(); // 未认证车主
    if (authenticationStatus == '0010') return _auditProgress(); // 审核中
    if (authenticationStatus == '0020') return _auditFailed(); // 审核失败
    return Container();
  }

  /// 未注册状态
  Widget _unregisteredStatus() {
    return Container(
      decoration: BoxDecoration(
        color: Color(0xffF6F8FC),
        borderRadius: BorderRadius.circular(ScreenUtil().setWidth(32)),
      ),
      child: Padding(
        padding: const EdgeInsets.only(left: 16, right: 16),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(height: ScreenUtil().setWidth(40.0)),
                Text(
                  '加入C20出行',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(32.0),
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(height: ScreenUtil().setWidth(20.0)),
                Text(
                  '让出行更简单',
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(28.0),
                      color: Color(0xff999999)),
                ),
              ],
            ),
            Container(
              width: ScreenUtil().setWidth(216.0),
              height: ScreenUtil().setWidth(80.0),
              decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                    colors: [
                      Color(0xff3FB956),
                      Color(0xff65CA00),
                    ],
                  ),
                  borderRadius: BorderRadius.all(
                      Radius.circular(ScreenUtil().setWidth(40)))),
              child: MaterialButton(
                // color: Colors.transparent,
                textColor: Colors.white,
                child: Text('立即注册'),
                onPressed: () =>
                    NavigatorUtil.jump(context, "/driverRegistration"),
              ),
            ),
          ],
        ),
      ),
    );
  }

  /// 审核失败
  Widget _auditFailed() {
    return Container(
      decoration: BoxDecoration(
        color: Color(0xffF6F8FC),
        borderRadius: BorderRadius.circular(ScreenUtil().setWidth(32)),
      ),
      child: Padding(
        padding: const EdgeInsets.only(left: 16, right: 16),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(height: ScreenUtil().setWidth(40.0)),
                Text(
                  '审核失败',
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(32.0),
                      fontWeight: FontWeight.w500,
                      color: Colors.red),
                ),
                SizedBox(height: ScreenUtil().setWidth(20.0)),
                Text(
                  '您的信息不全，请重新提交',
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(28.0),
                      color: Color(0xff999999)),
                ),
              ],
            ),
            Container(
              width: ScreenUtil().setWidth(216.0),
              height: ScreenUtil().setWidth(80.0),
              decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                    colors: [Color(0xff3FB956), Color(0xff65CA00)],
                  ),
                  borderRadius: BorderRadius.all(
                      Radius.circular(ScreenUtil().setWidth(40)))),
              child: MaterialButton(
                textColor: Colors.white,
                child: Text('查看'),
                onPressed: () =>
                    NavigatorUtil.jump(context, "/driverRegistration"),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 审核中
  Widget _auditProgress() {
    return Container(
      decoration: BoxDecoration(
        color: Color(0xffF6F8FC),
        borderRadius: BorderRadius.circular(ScreenUtil().setWidth(32)),
      ),
      child: Padding(
        padding: const EdgeInsets.only(left: 16, right: 16),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(height: ScreenUtil().setWidth(40.0)),
                Text(
                  '审核中',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(32.0),
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(height: ScreenUtil().setWidth(20.0)),
                Text(
                  '资料审核中，请耐心等待',
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(28.0),
                      color: Color(0xff999999)),
                ),
              ],
            ),
            Container(
              width: ScreenUtil().setWidth(216.0),
              height: ScreenUtil().setWidth(80.0),
              decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                    colors: [Color(0xff3FB956), Color(0xff65CA00)],
                  ),
                  borderRadius: BorderRadius.all(
                      Radius.circular(ScreenUtil().setWidth(40)))),
              child: MaterialButton(
                textColor: Colors.white,
                child: Text('查看'),
                onPressed: () =>
                    NavigatorUtil.jump(context, "/auditInProgress"),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 推荐宣传banner
  Widget propagandaBanner() {
    return Container(
      width: ScreenUtil().setWidth(700.0),
      height: ScreenUtil().setWidth(220.0),
      decoration: BoxDecoration(
        color: Colors.white,
        image: DecorationImage(
            image: AssetImage('assets/icon/home_advertising.png')),
      ),
    );
  }

  /// 常见问题
  Widget commonProblem() {
    return Container(
      width: ScreenUtil().setWidth(700.0),
      margin: EdgeInsets.all(ScreenUtil().setWidth(25.0)),
      padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(20.0)),
      decoration: BoxDecoration(
        color: Color(0xffF6F8FC),
        borderRadius: BorderRadius.circular(ScreenUtil().setWidth(32)),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          problemTitle(),
          problemList(),
        ],
      ),
    );
  }

  // 常见问题标题
  Widget problemTitle() {
    return Container(
      padding: EdgeInsets.all(ScreenUtil().setWidth(32.0)),
      width: ScreenUtil().setWidth(210),
      alignment: Alignment.centerLeft,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            width: ScreenUtil().setWidth(8),
            height: ScreenUtil().setWidth(28),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(ScreenUtil().setWidth(4)),
              color: Color(0xff3FB956),
            ),
          ),
          Text(
            '常见问题',
            style: TextStyle(
                color: Color(0xff333333),
                fontSize: ScreenUtil().setSp(30),
                fontWeight: FontWeight.w500),
          ),
        ],
      ),
    );
  }

  // 常见问题内容
  Widget problemList() {
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.only(
        left: ScreenUtil().setWidth(32.0),
        right: ScreenUtil().setWidth(32.0),
        top: ScreenUtil().setWidth(3),
        bottom: ScreenUtil().setWidth(12.5),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Container(
            alignment: Alignment.centerLeft,
            child: Text(
              '1.成为C20出行网约车司机的条件？',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(30.0),
                color: Color(0xff333333),
              ),
            ),
          ),
          SizedBox(height: ScreenUtil().setWidth(10.0)),
          Container(
            alignment: Alignment.centerLeft,
            child: Text(
              '年龄：男21-60周岁，女21-55周岁（部分城市女性年龄为21-60周岁）；驾驶证准驾车型;',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(28.0),
                color: Color(0xff999999),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
